package com.founder.android.http;

import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

/**
 * 图片HTTP请求包装类
 * @author chen_weihua
 *
 */
public class ImageCallbackWapper extends CallbackWrapper {
	
	private Bitmap bitmap;
	
	public ImageCallbackWapper(ResponseListener callbackActivity) {
		super(callbackActivity);
	}
	
	@Override
	protected void onResponseSuccess() {
		callbackActivity.onResponseSuccess(response, bitmap);
	}
	
	@Override
	protected void setResult() throws Exception {
		HttpEntity entity = response.getEntity();
		byte[] respBytes = EntityUtils.toByteArray(entity);
		bitmap = BitmapFactory.decodeByteArray(respBytes, 0, respBytes.length);
		if (bitmap == null || bitmap.getHeight() <= 0 || bitmap.getWidth() <= 0) {
			throw new Exception("bitmap decode failed!");
		}
	}
}
